﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class JLTVK16Data : BaseFunction
    {
        
        public JLTVK16Data()
            : base()
        {

        }
        public JLTVK16Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetVK16(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "VK16";
            string ART = dwABPOS["ART"].ToString().Trim();
            string FROMDNDATE = dwABPOS["FROMDNDATE"].ToString().Trim();
            string ENDDNDATE = dwABPOS["ENDDNDATE"].ToString().Trim();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "select a.vkpart as article,a.vkpfarbe as color,a.vkpmenge1*0.01 as qty, "
                    + " a.vkpmeeh as unit,a.vkpliefterm as deldate,a.vkpverzterm1 as gdate, "
                    + " a.vkpverzterm2 as fdate,a.vkpverzterm3 as edate, "
                    + " a.vkpverzterm4 as jdate,a.vkpverzterm5 as cdate, "
                    + " a.VKPVERZTERM3 as rsjsdate,a.VKPBESTTERM3 as rswsdate,a.VKPBESTTERM5 as kdate,vkpverzterm5 as ldate,a.vkpverzterm4 as mdate"
                    + " from vkpos a "
                    + " where a.vkpsa <> 'AJ' "
                    + " and a.vkpmandant='00' "
                    + " and a.vkpart LIKE  '"+ART+"%' "
                    + " AND a.vkpliefterm >= '" + FROMDNDATE + "' and a.vkpliefterm <= '" + ENDDNDATE + "' "                    
                    + " ORDER BY DELDATE,ARTICLE,COLOR "
                    ;
               
                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    //byte[] b;
                    //string value;
                    //foreach (DataRow dw in Result.Tables[TableName].Rows)
                    //{
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["BEM"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["BEM"] = value;
                    //    b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["DES"].ToString().Trim());
                    //    value = Encoding.GetEncoding("gb2312").GetString(b);
                    //    dw["DES"] = value;
                    //}
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }       
        public DataSet BuildJLTVK16Data(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetVK16(dwUI);
                setReturn.Merge(setResult);                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}